package leetcode_top;

import org.junit.Test;

public class Ex326 {
    class Solution {
        public boolean isPowerOfThree(int n) {
            while (n >= 3) {
                if (n / 3 * 3 == n) {
                    n /= 3;
                } else return false;
            }
            return n == 1;
        }

        public boolean isPowerOfThree2(int n) {
            if (n > 0 && 1162261467 % n == 0) { //1162261467是integer范围内3的整数幂最大的数，因此只要再整数范围内都是他的因数
                return true;
            } else return false;
        }
    }

    //  return True if(n>0 and 1162261467 % n == 0)else False
    @Test
    public void test() {
        Solution s = new Solution();
        System.out.println(s.isPowerOfThree(0));
    }
}
